<?php

namespace app\api\model;

class UserCode extends \app\admin\model\model\system\UserCode
{

    public static function send($phone, $code) {
        return self::addCommon([
            'phone' => $phone,
            'code'  => $code,
        ]);
    }

    public static function check($phone, $code) {
        $time = time() - 60*5;
        $where = [
            ['phone', '=', $phone],
            ['code', '=', $code],
            ['used', '=', self::USED_NO],
            ['create_time', '>', $time],
        ];
        return self::getLineCommon($where, '*', 'id desc');
    }

    public static function changeUse($id) {
        $data = [
            'id'    => $id,
            'used'  => self::USED_YES,
        ];
        return self::updateCommon($data);
    }

    public function getId() {
        return $this->getData('id');
    }
}